# 读取mdh文件

import SimpleITK as sitk
import matplotlib.pyplot as plt
import numpy as np
import os
import matplotlib.pyplot as plt


def readmdh():
    print(1)
    arterial_file_name = "E:\Dataset\Liver\DongBeiDaXue\\image_arterial\data2_0008_arterial.mha"
    arterial_image = sitk.ReadImage(arterial_file_name)
    arterial = sitk.GetArrayFromImage(arterial_image)

    print(2)
    venous_file_name = "E:\Dataset\Liver\DongBeiDaXue\\image_venous\data2_0008_venous.mha"
    venous_image = sitk.ReadImage(venous_file_name)
    venous = sitk.GetArrayFromImage(venous_image)

    print(3)
    lesion_file_name = "E:\Dataset\Liver\DongBeiDaXue\lesion\data2_0008_lesion_label.mha"
    lesion_image = sitk.ReadImage(lesion_file_name)
    lesion = sitk.GetArrayFromImage(lesion_image)


    print(4)
    plt.subplot(1, 4, 1)
    plt.imshow(arterial[0], cmap="gray")
    arterial[arterial <= -200] = -200
    arterial[arterial > 200] = 200
    plt.subplot(1, 4, 2)
    plt.imshow(arterial[0], cmap="gray")
    plt.subplot(1, 4, 3)
    plt.imshow(venous[0], cmap="gray")
    venous[venous <= -200] = -200
    venous[venous  > 200] = 200
    plt.subplot(1, 4, 4)
    plt.imshow(venous[0], cmap="gray")
    plt.show()


def read_artery_vein():
    venous = "E:\Dataset\Liver\qiye\DongBeiDaXue2\image_venous\\data2_0865_venous.mha"
    artery = "E:\Dataset\Liver\qiye\DongBeiDaXue2\image_arterial\\data2_0865_arterial.mha"

    arterial_image = sitk.ReadImage(artery)
    arterial = sitk.GetArrayFromImage(arterial_image)

    venous_image = sitk.ReadImage(venous)
    venous = sitk.GetArrayFromImage(venous_image)

    arterial[arterial <= -250] = -250
    arterial[arterial > 250] = 250

    venous[venous <= -250] = -250
    venous[venous > 250] = 250

    print(arterial.shape, venous.shape)

    plt.subplot(1, 2, 1)
    plt.imshow(arterial[264], cmap="gray")
    plt.subplot(1, 2, 2)
    plt.imshow(venous[264], cmap="gray")
    plt.show()







if __name__ == '__main__':
    read_artery_vein()